package com.sanyuan.cloud.module.system.dal.mysql.nongmo;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sanyuan.cloud.framework.mybatis.core.mapper.BaseMapperX;
import com.sanyuan.cloud.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.sanyuan.cloud.module.system.controller.admin.nongmo.req.PositionListReq;
import com.sanyuan.cloud.module.system.controller.admin.nongmo.vo.PositionListVO;
import com.sanyuan.cloud.module.system.controller.app.position.req.PositionReqVO;
import com.sanyuan.cloud.module.system.dal.dataobject.nongmo.SystemPositionDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;

/**
* @author szw
* @description 针对表【system_position(标点位置信息)】的数据库操作Mapper
* @createDate 2025-03-20 15:14:20
* @Entity generator.domain.SystemPosition
*/
@Mapper
public interface SystemPositionMapper extends BaseMapperX<SystemPositionDO> {

    IPage<PositionListVO> selectPositionUserByPage(IPage<SystemPositionDO> pag, @Param("req") PositionListReq req);

    default SystemPositionDO updateById(Long id, String userId){
        SystemPositionDO entity = this.selectById(id);
        if (null == entity){
            return null;
        }
        entity.setDeleted(true);
        entity.setUpdater(userId);
        entity.setUpdateTime(LocalDateTime.now());
        update(new LambdaUpdateWrapper<>(SystemPositionDO.class)
                .eq(SystemPositionDO::getId,id)
                .set(SystemPositionDO::getDeleted,1)
        );
        return entity;
    }

    default SystemPositionDO selectEntityOne(PositionReqVO reqVO){
        return selectOne(new LambdaQueryWrapperX<SystemPositionDO>()
                .eqIfPresent(SystemPositionDO::getName, reqVO.getName())
        );
    }

    default SystemPositionDO insertEntity(SystemPositionDO entity){
        this.insert(entity);
        return entity;
    }

    default Long countPosition(){
        return selectCount();
    }
}




